package com.controller.manager;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import com.service.RegistrationRecordService;

@Controller
@RequestMapping("/registrationRecord")
public class RegistrationRecordController {

	@Resource
	private RegistrationRecordService registrationRecordService;

	@RequestMapping(value = "/addRegistrationRecordInfo", method = RequestMethod.POST)
	@ResponseBody
	public String addRegistrationRecordInfo(@RequestParam Map<String, String> paramsMap,
			@RequestParam(value = "imgfiles", required = false) MultipartFile[] imgfiles) {
		try {
			int result = registrationRecordService.addRegistrationRecordInfo(paramsMap, imgfiles);
			if (result > 0) {
				return "success";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "error";
	}

	// 删除
	@RequestMapping(value = "/deleteRegistrationRecordInfo", method = RequestMethod.POST)
	@ResponseBody
	public String deleteRegistrationRecordInfo(@RequestParam Map<String, String> paramsMap) {
		try {
			int result = registrationRecordService.deleteRegistrationRecordInfo(paramsMap);
			if (result >= 0) {
				return "success";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "error";
	}

	@RequestMapping(value = "/updateRegistrationRecordInfo", method = RequestMethod.POST)
	@ResponseBody
	public String updateRegistrationRecordInfo(@RequestParam Map<String, String> paramsMap,
			@RequestParam(value = "imgfiles", required = false) MultipartFile[] imgfiles) {
		try {

			int result = registrationRecordService.updateRegistrationRecordInfo(paramsMap,imgfiles);
			if (result > 0) {
				return "success";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "error";
	}

	// 查询
	@RequestMapping(value = "/getRegistrationRecordInfo", method = RequestMethod.GET)
	@ResponseBody
	public List<Map<String, String>> getRegistrationRecordInfo(@RequestParam Map<String, String> paramsMap) {
		try {
			List<Map<String, String>> list = registrationRecordService.getRegistrationRecordInfo(paramsMap);
			return list;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	@RequestMapping(value = "/getRegistrationRecord", method = RequestMethod.GET)
	@ResponseBody
	public ModelAndView getRegistrationRecord(HttpServletRequest request, @RequestParam Map<String, String> paramsMap) {
		request.setAttribute("deviceid", paramsMap.get("deviceid"));
		return new ModelAndView("/manager/index.five");
	}
	
	@RequestMapping(value = "/getRegistrationRecordByDeviceId", method = RequestMethod.GET)
	@ResponseBody
	public ModelAndView getRegistrationRecordByDeviceId(HttpServletRequest request, @RequestParam Map<String, String> paramsMap) {
		Map<String, String> deviceid =  registrationRecordService.getRegistrationRecordByDeviceId(paramsMap);
		Map<String, String> map = registrationRecordService.getPassword(paramsMap);
		request.setAttribute("deviceid", deviceid);
		request.setAttribute("map", map);
		return new ModelAndView("/manager/index_five_az");
	}
	@RequestMapping(value = "/getRegistrationRecordByDeviceIdWx", method = RequestMethod.GET)
	@ResponseBody
	public ModelAndView getRegistrationRecordByDeviceIdWx(HttpServletRequest request, @RequestParam Map<String, String> paramsMap) {
		Map<String, String> deviceid =  registrationRecordService.getRegistrationRecordByDeviceId(paramsMap);
		Map<String, String> map = registrationRecordService.getPassword(paramsMap);
		request.setAttribute("map", map);
		request.setAttribute("deviceid", deviceid);
		return new ModelAndView("/manager/index_five_wx");
	}
	
	@RequestMapping(value = "/getRegistrationRecordByDeviceIdXj", method = RequestMethod.GET)
	@ResponseBody
	public ModelAndView getRegistrationRecordByDeviceIdXj(HttpServletRequest request, @RequestParam Map<String, String> paramsMap) {
		Map<String, String> deviceid = registrationRecordService.getRegistrationRecordByDeviceId(paramsMap);
		Map<String, String> map = registrationRecordService.getPassword(paramsMap);
		request.setAttribute("map", map);
		request.setAttribute("deviceid", deviceid);
		return new ModelAndView("/manager/index_five_xj");
	}

}
